/**
 * Copyright (c) 2016 NumberFour AG.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   NumberFour AG - Initial API and implementation
 */
package org.eclipse.n4js.transpiler.es.tests;

import org.eclipse.n4js.N4JSInjectorProvider;
import org.eclipse.n4js.n4JS.Script;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;

@RunWith(XtextRunner.class)
@InjectWith(N4JSInjectorProvider.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class GH_2350_SetterWithReturnTest extends AbstractTranspilerTest {

	@Test
	public void test_Compile() throws Throwable {
		String script = """
				interface IS {
				    myValue:string;
				    set setter(value : string) {
				        this.myValue = value;
				    }
				}

				class MyClass implements IS {
				}
				""";

		String moduleWrapped = """
				// Generated by N4JS transpiler; for copyright see original N4JS source file.

				import 'n4js-runtime'

				const IS = {
					$fieldInits: {
						myValue: undefined
					},
					$defaultMembers: {
						set setter(value) {
							this.myValue = value;
						}
					},
					[Symbol.hasInstance](instance) {
						return instance && instance.constructor && instance.constructor.n4type && instance.constructor.n4type.allImplementedInterfaces && instance.constructor.n4type.allImplementedInterfaces.indexOf('__synthetic0/IS') !== -1;
					},
					get n4type() {
						return $getReflectionForInterface(this, '["IS","__synthetic0","TestProject"]');
					}
				};
				class MyClass extends N4Object {
					constructor() {
						super();
						$initFieldsFromInterfaces(this, MyClass, undefined, {
							n4type: true
						});
					}
					set setter(value) {
						Object.getOwnPropertyDescriptor(IS.$defaultMembers, 'setter').set.apply(this, arguments);
					}
					static get n4type() {
						return $getReflectionForClass(this, '["MyClass","__synthetic0","TestProject",["s:setter","f:myValue"]]');
					}
					static get $implements() {
						return [
							IS
						];
					}
				}
				""";

		Script scriptNode = parseHelper.parse(script);
		resolveLazyRefs(scriptNode);
		assertCompileResult(scriptNode, moduleWrapped);
	}

}
